﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KOPLibrary.Forms.CashFlow
{
    public partial class FlowFilterUc : UserControl
    {
        public FlowFilterUc()
        {
            InitializeComponent();
        }

        internal void Bind(BindingSource source, string dataMember)
        {
            ctlFilterDestAcc.Init(source, dataMember);
            ctlFilterSourceAcc.Init(source, dataMember);
        }

        internal string GetLocalFilterExpression()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("1 = 1");
            if (ctlUseFilterStart.Checked)
                sb.Append(string.Format("and Tarih >= '{0}'", ctlFilterDate1.Value.Date));
            if (ctlUseFilterFinish.Checked)
                sb.Append(string.Format("and Tarih <= '{0}'", ctlFilterDate2.Value.Date.AddHours(23).AddMinutes(59).AddSeconds(59)));
            
            if (ctlUseFilterSourceMain.Checked)
                sb.Append(string.Format(" and [Kaynak Ana Hesap ID] = '{0}'", ctlFilterSourceAcc.SelectedParentID));
            if (ctlUseFilterSource.Checked)
                sb.Append(string.Format(" and [Kaynak Hesap ID] = '{0}'", ctlFilterSourceAcc.SelectedID));

            if (ctlUseFilterDest.Checked)
                sb.Append(string.Format(" and [Hedef Hesap ID] = '{0}'", ctlFilterDestAcc.SelectedID));
            if (ctlUseFilterDestMain.Checked)
                sb.Append(string.Format(" and [Hedef Ana Hesap ID] = '{0}'", ctlFilterDestAcc.SelectedParentID));

            string filter = sb.ToString();

            if (filter == "1 = 1")
                return "";
            else return filter;
        }

        private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
